import Vue from "vue"
import VueRouter from 'vue-router'
Vue.use(VueRouter)

// import loginPage from '../views/login'

const routes = [
    { path: '/',redirect:'/Login'},
    { 
        path: '/index', 
        component:() => import('../views/index'),
        children:[
            { name:"banner",path: 'banner', component: () => import("../views/shouye/banner"),meta:{ title:'轮播图管理'} },
            { name:"category",path: 'category', component: () => import("../views/shouye/category"),meta:{ title:'分类区管理'} },
            { name:"recommend",path: 'recommend', component: () => import("../views/shouye/recommend"),meta:{ title:'为你推荐管理'} },
            { name:"shouye", path: 'shouye', component: () => import("../views/shouye/shouye"),meta:{ title:'欢迎！'} },
            { name:"categories", path: 'categories', component: () => import("../views/shouye/categories"),meta:{ title:'商品分类'} },
            { name:"brand", path: 'brand', component: () => import("../views/shouye/brand"),meta:{ title:'品牌管理'} },
            { name:"onegoods", path: 'onegoods', component: () => import("../views/shouye/onegoods"),meta:{ title:'单品管理'} },
            { name:"goods", path: 'goods', component: () => import("../views/shouye/goods"),meta:{ title:'商品管理'} },
            { name:"news", path: 'news', component: () => import("../views/shouye/news"),meta:{ title:'新闻管理'}}
        ]
    },
    { path: '/login', component: () => import("../views/Login"),meta:{ title:'登陆'} }
]

const router = new VueRouter({
    // mode:"history",
    routes // `routes: routes` 的缩写
})

// 路由前置导航守卫
router.beforeEach((to, from, next) => {
    /* 路由发生变化修改页面title */
    if (to.meta.title) {
      document.title = to.meta.title
    }
    next()
})  

export default router
